import os
import pydicom
import numpy as np


def process_dicom_file(file_path):
    # 读取DICOM文件
    dicom_file = pydicom.dcmread(file_path)

    # 获取像素数组
    pixel_data = dicom_file.pixel_array

    # 打印像素数组的最大值
    max_value = np.max(pixel_data)

    min_value = np.min(pixel_data)
    window = max_value
    level = (max_value + min_value) / 2
    print("min:", min_value, "\t\tlevel :", level,
          "\nmax:", max_value, "\twindow:", window)


# def process_dicom_files_in_folder(folder_path):
#     # 遍历文件夹中的所有文件
#     for filename in os.listdir(folder_path):
#         # 检查文件是否是DICOM文件
#         if filename.endswith(".dcm"):
#             file_path = os.path.join(folder_path, filename)
#             process_dicom_file(file_path)


if __name__ == "__main__":
    image_path = r"C:\develop\GraduationDesign\medical-image-preprocessing\test\CYJ-13-28.dcm"
    process_dicom_file(image_path)
